﻿using AutoMapper;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using TrackSystem.Contracts;
using TrackSystem.Entities.Extensions;
using TrackSystem.IO.Formula;
using TrackSystem.IO.Utils;

namespace TrackSystem.API.Controllers
{
    /// <summary>
    /// 逻辑表达式控制器
    /// </summary>
    [Route("api/logic")]
    [ApiController]
    public class LogicDefController : ControllerBase
    {
        private readonly IRepositoryWrapper wrapper;
        private readonly IMapper mapper;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="wrapper"></param>
        /// <param name="mapper"></param>
        public LogicDefController(IRepositoryWrapper wrapper, IMapper mapper)
        {
            this.wrapper = wrapper;
            this.mapper = mapper;
        }

        /// <summary>
        /// 测试表达式
        /// </summary>
        /// <param name="formula"></param>
        /// <returns></returns>
        [HttpGet("test")]
        public async Task<FormulaResult> TestFormula(string formula)
        {
            var varList = await wrapper.Var.GetNameTypeListAsync();
            var outList = new Dictionary<string, DataTypeEnum>();
            var result = PageAnalysis.TestPageFormula(formula, varList, out outList);
            return result;
        }
    }
}
